home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / c / EasygadgetsSou.lha / EasyGadgets / HandleKeys.c_backup < prev    next >
Text File  |  1995-10-13  |  22KB  |  876 lines

  1. /*
  2.  *    File:                    HandleKeys.c
  3.  *    Description:    Handle vanilla shortcuts for gadgets
  4.  *
  5.  *    (C) 1995, Ketil Hunn
  6.  *
  7.  */
  8.  
  9. #ifndef EG_HANDLEKEYS_H
  10. #define EG_HANDLEKEYS_H
  11.  
  12. /*** PRIVATE INCLUDES ****************************************************************/
  13. #ifndef CLIB_INTUITION_PROTOS_H
  14. #include <clib/intuition_protos.h>
  15. #endif
  16.  
  17. #ifndef CLIB_GADTOOLS_PROTOS_H
  18. #include <clib/gadtools_protos.h>
  19. #endif
  20.  
  21. /*** DEFINES *************************************************************************/
  22. #define    every_node    node=list->lh_Head;node->ln_Succ;node=node->ln_Succ
  23.  
  24. #define SHIFTPRESSED(msg)    ((msg->Qualifier & IEQUALIFIER_LSHIFT) | (msg->Qualifier & IEQUALIFIER_RSHIFT))
  25. #define ALTPRESSED(msg)        ((msg->Qualifier & IEQUALIFIER_LALT) | (msg->Qualifier & IEQUALIFIER_RALT))
  26. #define CTRLPRESSED(msg)    (msg->Qualifier & IEQUALIFIER_CONTROL)
  27.  
  28. /*** PROTOTYPES **********************************************************************/
  29. __asm void egCloseAllTasks(register __a0 struct EasyGadgets    *eg);
  30.  
  31. /*** FUNCTIONS ***********************************************************************/
  32.  
  33. __asm ULONG egHookEntry(register __a0 struct Hook *hook,
  34.                                                 register __a2 VOID *o,
  35.                                                 register __a1 VOID *msg)
  36. {
  37. #ifdef MYDEBUG_H
  38.     DebugOut("egHookEntry");
  39. #endif
  40.     return ((*(ULONG (*)(struct Hook *,VOID *,VOID *))(hook->h_SubEntry))(hook, o, msg));
  41. }
  42.  
  43. __asm VOID egInitHook(register __a0 struct Hook        *hook,
  44.                                             register __a2 ULONG                    (*func)(),
  45.                                             register __a1 APTR                    data)
  46. {
  47. #ifdef MYDEBUG_H
  48.     DebugOut("egInitHook");
  49. #endif
  50.     if(hook)
  51.     {
  52.         hook->h_Entry        =(ULONG (*)()) egHookEntry;
  53.         hook->h_SubEntry=func;
  54.         hook->h_Data        =data;
  55.     }
  56. }
  57.  
  58. __asm ULONG egCallHook(    register __a0 void    *func,
  59.                                                 register __a1 APTR    msg)
  60. {
  61.     struct Hook    hook;
  62.     ULONG retvalue=1;
  63.  
  64. #ifdef MYDEBUG_H
  65.     DebugOut("egCallHook");
  66. #endif
  67.  
  68.     if(func)
  69.     {
  70.         egInitHook(&hook, func, msg);
  71.         retvalue=CallHookA(&hook, NULL, msg);
  72.     }
  73.     return retvalue;
  74. }
  75.  
  76. __asm __saveds UWORD egCountList(register __a0 struct List *list)
  77. {
  78.     register struct Node *node;
  79.     register UWORD count=0;
  80.  
  81.     for(every_node)
  82.         ++count;
  83.  
  84.     return count;
  85. }
  86.  
  87. void egGetGadgetAttrs(struct egGadget     *newgad,
  88.                                             struct Window            *win,
  89.                                             struct Requester    *req,
  90.                                             Tag                                tag1, ...)
  91. {
  92.     egGetGadgetAttrsA(newgad, win, req, (struct TagItem *)&tag1);
  93. }
  94.  
  95. __asm __saveds LONG egHandleListviewArrows(register __a1 struct egGadget             *listview,
  96.                                                                                         register __a0 struct Window                *window,
  97.                                                                                         register __a2 struct IntuiMessage *msg)
  98. {
  99.     register WORD        scrollrows=(H(listview)/listview->ng.ng_TextAttr->ta_YSize)-1, addon=1;
  100.     register UWORD    count=egCountList(listview->list);
  101.     register BYTE        highkick=(KickStart>38),
  102.                                     readonly=ISBITSET(listview->flags, EG_READONLY);
  103.     ULONG    top=0;
  104.  
  105.     if(listview->active==EG_LISTVIEW_NONE)
  106.     {
  107.         listview->active=0L;
  108.         addon=0;
  109.     }
  110.  
  111.     if(highkick)
  112.         GT_GetGadgetAttrs(listview->gadget, window, NULL,
  113.                                             GTLV_Top,    &top,
  114.                                             TAG_DONE);
  115.  
  116.     switch(msg->Code)
  117.     {
  118.         case CURSORUP:
  119.             if(CTRLPRESSED(msg) | ALTPRESSED(msg))
  120.             {
  121.                 listview->active=0L;
  122. //                listview->min=0;
  123.             }
  124.             else if(SHIFTPRESSED(msg))
  125.             {
  126.                 if(readonly)
  127.                     listview->active=MIN(0, listview->active-scrollrows-1);
  128.                 else
  129.                 {
  130.                     if(highkick==TRUE & listview->active>top)
  131.                         listview->active=(LONG)top;
  132.                     else
  133.                     {
  134.                         listview->active=(LONG)MAX(0L, listview->active-scrollrows);
  135. //                        listview->min=(listview->active<listview->min-scrollrows ? listview->active:listview->min);
  136.                     }
  137.                 }
  138.             }
  139.             else
  140.             {
  141.                 if(readonly)
  142.                     listview->active=MAX(0, listview->active-1);
  143.                 else
  144.                 {
  145.                     if(ISBITSET(listview->flags, EG_READONLY))
  146.                         top=MAX(0, top-1);
  147.                     else
  148.                     {
  149.                         listview->active=(LONG)MAX(0L, listview->active-addon);
  150. //                        listview->min=(listview->active<listview->min ? listview->min-(listview->min-listview->active): listview->min);
  151.                     }
  152.                 }
  153.             }
  154.             break;
  155.         case CURSORDOWN:
  156.             if(CTRLPRESSED(msg) | ALTPRESSED(msg))
  157.             {
  158.                 listview->active=(LONG)count-1;
  159. //                listview->min=count;
  160.             }
  161.             else if(SHIFTPRESSED(msg))
  162.             {
  163.                 if(readonly)
  164.                     listview->active=MIN(count-1, listview->active+scrollrows-1);
  165.                 else
  166.                 {
  167.                     if(highkick==TRUE & listview->active!=top+scrollrows)
  168.                         listview->active=(LONG)MIN(count-1, (UWORD)top+scrollrows);
  169.                     else
  170.                     {
  171.                         listview->active=(LONG)MIN(count-1, listview->active+scrollrows);
  172. //                        listview->min=MIN(count-1, listview->min+scrollrows-1);
  173.                     }
  174.                 }
  175.             }
  176.             else
  177.             {
  178.                 if(readonly)
  179.                     listview->active=MIN(count-1, listview->active+scrollrows);
  180.                 else
  181.                 {
  182.                     listview->active=(LONG)MIN(count-1, listview->active+addon);
  183. //                    listview->min=(listview->active>listview->min+scrollrows ? listview->min+1: listview->min);
  184.                 }
  185.             }
  186.             break;
  187.     }
  188.  
  189.     GT_SetGadgetAttrs(listview->gadget, window, NULL,
  190.                             GTLV_Selected,                                                                            (UWORD)listview->active,
  191.                             (highkick | !readonly ? GTLV_MakeVisible:GTLV_Top),    (UWORD)listview->active,
  192.                             TAG_DONE);
  193.  
  194.     return listview->active;
  195. }
  196.  
  197. __asm __saveds UBYTE egFindVanillaKey(register __a0 char *text)
  198. {
  199.     register UBYTE *c;
  200. #ifdef MYDEBUG_H
  201.     DebugOut("egFindVanillaKey");
  202. #endif
  203.  
  204.     if(c=StrChr(text, EG_Underscorechar))
  205.             return(ToUpper(*(c+1)));
  206.  
  207.     return 1;
  208. }
  209.  
  210. __asm struct egGadget *egMatchKey(register __a0 struct egGadget *gad,
  211.                                                                     register __d0 UBYTE                        key)
  212. {
  213.     register struct egGadget *found=NULL;
  214.  
  215. #ifdef MYDEBUG_H
  216.     DebugOut("egMatchKey");
  217. #endif
  218.  
  219.     if(key!=NULL)
  220.         while(gad!=NULL)
  221.         {
  222.             if(gad->key==key)
  223.             {
  224.                 found=gad;
  225.                 break;
  226.             }
  227.             gad=gad->NextGadget;
  228.         }
  229.     return found;
  230. }
  231.  
  232. __asm struct egGadget *egFindListview(register __a0 struct egGadget *gad)
  233. {
  234.     register struct egGadget *found=NULL;
  235.  
  236. #ifdef MYDEBUG_H
  237.     DebugOut("egFindListview");
  238. #endif
  239.  
  240.     while(gad!=NULL)
  241.     {
  242.         if(ISBITSET(gad->flags, EG_LISTVIEWARROWS))
  243.         {
  244.             found=gad;
  245.             break;
  246.         }
  247.         gad=gad->NextGadget;
  248.     }
  249.     return found;
  250. }
  251.  
  252. __asm struct egGadget *egFindGadget(register __a0 struct egGadget *gad,
  253.                                                                         register __d0 UWORD                        id)
  254. {
  255.     register struct egGadget *found=NULL;
  256.  
  257. #ifdef MYDEBUG_H
  258.     DebugOut("egFindGadget");
  259. #endif
  260.  
  261.     while(gad)
  262.     {
  263.         if(gad->ng.ng_GadgetID==id)
  264.         {
  265.             found=gad;
  266.             break;
  267.         }
  268.         gad=gad->NextGadget;
  269.     }
  270.     return found;
  271. }
  272.  
  273. __asm __saveds void egSetGadgetState(    register __a0 struct egGadget *gadget,
  274.                                                                             register __a1 struct Window     *window,
  275.                                                                             register __d0 BYTE                        state)
  276. {
  277. #ifdef MYDEBUG_H
  278.     DebugOut("egSetGadgetState");
  279. #endif
  280.  
  281.     if(gadget!=NULL & window!=NULL)
  282.         if(ISBITSET(gadget->flags, EG_DISABLED)==FALSE)
  283.         {
  284.             UWORD gadpos=RemoveGadget(window, gadget->gadget);
  285.             IFTRUESETBIT(state, gadget->gadget->Flags, GFLG_SELECTED);
  286.             AddGadget(window, gadget->gadget, gadpos);
  287.             RefreshGList(gadget->gadget, window, NULL, 1);
  288.         }
  289. }
  290.  
  291. __asm __saveds UBYTE egConvertRawKey(register __a0 struct IntuiMessage *msg)
  292. {
  293.     static struct InputEvent ev;
  294.     UBYTE buffer[9];
  295.     int len;
  296.  
  297. #ifdef MYDEBUG_H
  298.     DebugOut("egConvertRawKey");
  299. #endif
  300.  
  301.     if(msg->Class!=IDCMP_RAWKEY)
  302.         return 0;
  303.  
  304.     ev.ie_Class                  =IECLASS_RAWKEY;
  305.     ev.ie_Code               =msg->Code;
  306.     ev.ie_Qualifier     =msg->Qualifier;
  307.     ev.ie_EventAddress=*(APTR *)msg->IAddress;
  308.     len=MapRawKey(&ev, buffer, 8, NULL);
  309.     if(len!=1)
  310.         return 0;
  311.     return buffer[0];
  312. }
  313.  
  314. __asm void egHandleMultipleChoiceKind(register __a0 struct IntuiMessage *msg,
  315.                                                                             register __a1 struct egTask                *task,
  316.                                                                             register __d0 BYTE                                shift)
  317. {
  318.     if(shift)
  319.     {
  320.         if(task->activegad->active==0L)
  321.         {
  322.             if(task->activegad->kind==PALETTE_KIND)
  323.                 ;//msg->Code=1<<eg->RPort.BitMap->Depth;
  324.             else
  325.             {
  326.                 for(msg->Code=0; task->activegad->labels[msg->Code]!=NULL; msg->Code++)
  327.                     ;
  328.             }
  329.             --msg->Code;
  330.         }
  331.         else
  332.             msg->Code=task->activegad->active-1;
  333.     }
  334.     else
  335.     {
  336.         if(task->activegad->labels[task->activegad->active+1]==NULL)
  337.             msg->Code=0;
  338.         else
  339.             msg->Code=task->activegad->active+1;
  340.     }
  341.     task->activegad->active=(LONG)msg->Code;
  342.     GT_SetGadgetAttrs(task->activegad->gadget, task->window, task->req,
  343.                         GTCY_Active,    msg->Code,
  344.                         GTMX_Active,    msg->Code,
  345.                         TAG_DONE);
  346.     CLEARBIT(msg->Class, IDCMP_RAWKEY);
  347.     if(task->activegad->kind==MX_KIND)
  348.         SETBIT(msg->Class, IDCMP_GADGETDOWN);
  349.     else
  350.         SETBIT(msg->Class, IDCMP_GADGETUP);
  351.     msg->IAddress=task->activegad->gadget;
  352. }
  353.  
  354. __asm __saveds ULONG egWait(register __a0 struct EasyGadgets *eg,
  355.                                                         register __d0 ULONG                                signals)
  356. {
  357.      register ULONG signal=Wait(    signals                                |
  358.                                                             eg->AmigaGuideSignal    |
  359.                                                             1L<<eg->msgport->mp_SigBit);
  360.     if(signal & eg->AmigaGuideSignal)
  361.         egHandleAmigaGuide(eg);
  362.     if(signal & 1L<<eg->msgport->mp_SigBit)
  363.         egGetMsg(eg);
  364.  
  365.     return signal;
  366. }
  367.  
  368. __asm __saveds struct IntuiMessage *egGetMsg(register __a0 struct EasyGadgets    *eg)
  369. {
  370.     struct IntuiMessage *tmpmsg, *msg=NULL;
  371.     register struct egTask                *task;
  372.  
  373. #ifdef MYDEBUG_H
  374.     DebugOut("egGetMsg");
  375. #endif
  376.  
  377.     if(ISBITSET(eg->flags, EG_ICONIFIED))
  378.     {
  379.         register struct Message *msg;
  380.  
  381.         if(msg=GetMsg(eg->msgport))
  382.         {
  383.             ReplyMsg(msg);
  384.             egIconify(eg, FALSE);
  385.         }
  386.     }
  387.  
  388.     while(!IsNil(&eg->msgport->mp_MsgList))
  389.     {
  390.         switch(eg->msgport->mp_MsgList.lh_Head->ln_Type)
  391.         {
  392.             case NT_USER:
  393.                 break;
  394.             case EG_INTUIMSG:
  395.                 if(msg=GetMsg(eg->msgport))
  396.                 {
  397.                     CopyMem((struct IntuiMessage *)msg, eg->msg, sizeof(struct IntuiMessage));
  398.                     for(task=eg->tasklist; task; task=task->nexttask)
  399.                     {
  400.                         if(task->status==STATUS_OPEN & task->window==msg->IDCMPWindow && task->handlefunc)
  401.                             egCallHook(task->handlefunc, (APTR)eg);
  402.                         break;
  403.                     }
  404.                     FreeVec(msg);
  405.                 }
  406.                 break;
  407.             default:
  408.                 if(tmpmsg=GT_GetIMsg(eg->msgport))
  409.                 {
  410.                     CopyMem(tmpmsg, eg->msg, sizeof(struct IntuiMessage));
  411.                     GT_ReplyIMsg(tmpmsg);
  412.                     msg=eg->msg;
  413.  
  414.         for(task=eg->tasklist; task; task=task->nexttask)
  415.             if(task->status==STATUS_OPEN & task->window==msg->IDCMPWindow)
  416.             {
  417.                 switch(msg->Class)
  418.                 {
  419.                     case IDCMP_REFRESHWINDOW:
  420.                         GT_BeginRefresh(task->window);
  421.                         if(task->refreshfunc)
  422.                             egCallHook(task->refreshfunc, (APTR)msg);
  423.                         GT_EndRefresh(task->window, TRUE);
  424.                         break;
  425.                     case IDCMP_SIZEVERIFY:
  426.                         egFreeGList(task);
  427.                         RefreshWindowFrame(task->window);
  428.                         break;
  429.                     case IDCMP_NEWSIZE:
  430.                         if(task->renderfunc)
  431.                         {
  432.                             if(task->glist)
  433.                                 egFreeGList(task);
  434.                             eg->dri=task->dri;
  435.                             egCallHook(task->renderfunc, (APTR)msg);
  436.                             egRenderGadgets(task);
  437.                         }
  438.                         if(task->refreshfunc)
  439.                             egCallHook(task->refreshfunc, (APTR)msg);
  440.                         break;
  441.                     case IDCMP_CLOSEWINDOW:
  442.                         if(task==task->eg->tasklist)
  443.                             egCloseAllTasks(task->eg);
  444.                         else
  445.                             egCloseTask(task);
  446.                         break;
  447.  
  448.                     case IDCMP_MENUHELP:
  449.                         {
  450.                             UBYTE title[MAXCHARS];
  451.                             register struct Menu *menu=task->window->MenuStrip;
  452.                             register ULONG count=MENUNUM(msg->Code);
  453.  
  454.                             for(; menu!=NULL & count-->0; menu=menu->NextMenu)
  455.                                 ;
  456.                             if(menu)
  457.                             {
  458.                                 sprintf(title, "Menu_%ld", MENUNUM(msg->Code)+1);
  459.                                 egShowAmigaGuide(eg, title);
  460.                             }
  461.                         }
  462.                         break;
  463.                     case IDCMP_VANILLAKEY:
  464.                     case IDCMP_RAWKEY:
  465.                         if(msg->Code==CURSORUP | msg->Code==CURSORDOWN)
  466.                         {
  467.                             struct egGadget *listview;
  468.  
  469.                             if(listview=egFindListview(task->eglist))
  470.                             {
  471.                                 register UWORD oldactive=(UWORD)listview->active;
  472.  
  473.                                 if(oldactive!=(msg->Code=(UWORD)egHandleListviewArrows(listview, task->window, msg)))
  474.                                 {
  475.                                     CLEARBIT(msg->Class, IDCMP_RAWKEY);
  476.                                     SETBIT(msg->Class, IDCMP_GADGETUP);
  477.                                     msg->IAddress=listview->gadget;
  478.                                 }
  479.                             }
  480.                         }
  481.                         else if(msg->Code!=95)
  482.                         {
  483.                             int upstroke=msg->Code & 0x80;
  484.                             BYTE shift=(BYTE)((msg->Qualifier & IEQUALIFIER_LSHIFT) | (msg->Qualifier & IEQUALIFIER_RSHIFT));
  485.  
  486.                             if(task->activegad)    // key released
  487.                             {
  488.                                 int samekey=(msg->Code & 0x7f)==task->activekey;
  489.  
  490.                                 if(samekey && !upstroke)
  491.                                     break;
  492.  
  493.                                 egSetGadgetState(task->activegad, task->window, FALSE);
  494.  
  495.                                 if(samekey)
  496.                                 {
  497.                                     switch(task->activegad->kind)
  498.                                     {
  499.                                         case CYCLE_KIND:
  500.                                             egHandleMultipleChoiceKind(msg, task, shift);
  501.                                             break;
  502.                                         case BUTTON_KIND:
  503.                                         case EG_GETFILE_KIND:
  504.                                         case EG_GETDIR_KIND:
  505.                                         case EG_POPUP_KIND:
  506.                                             CLEARBIT(msg->Class, IDCMP_RAWKEY);
  507.                                             SETBIT(msg->Class, IDCMP_GADGETUP);
  508.                                             msg->IAddress=task->activegad->gadget;
  509.                                             break;
  510.                                     }
  511.                                 }
  512.                                 task->activegad=NULL;
  513.                                 task->activekey=0;
  514.                             }
  515.                             else // new key pressed
  516.                             {
  517.                                 UBYTE keypress=egConvertRawKey(msg);
  518.                                 struct egGadget *eggad=egMatchKey(task->eglist, ToUpper(keypress));
  519.  
  520.                                 if(eggad==NULL)
  521.                                     break;
  522.                                 if(ISBITSET(eggad->flags, EG_DISABLED))
  523.                                     break;
  524.  
  525.                                 switch(eggad->kind)
  526.                                 {
  527.                                     case BUTTON_KIND:
  528.                                     case EG_GETFILE_KIND:
  529.                                     case EG_GETDIR_KIND:
  530.                                     case EG_POPUP_KIND:
  531.                                     case CYCLE_KIND:
  532.                                         task->activegad=eggad;
  533.                                         task->activekey=msg->Code;
  534.                                         egSetGadgetState(eggad, task->window, TRUE);
  535.                                         msg=NULL;
  536.                                         break;
  537.                                     case STRING_KIND:
  538.                                     case INTEGER_KIND:
  539.                                         egActivateGadget(eggad, task->window, task->req);
  540.                                         break;
  541.                                     case SLIDER_KIND:
  542.                                     case SCROLLER_KIND:
  543.                                     case LISTVIEW_KIND:
  544.                                         {
  545.                                             register BYTE addon=1;
  546.                                             register LONG oldactive=eggad->active;
  547.  
  548.                                             if(eggad->kind==LISTVIEW_KIND)
  549.                                             {
  550.                                                 eggad->max=MAX(0, (egCountList(eggad->list)-1));
  551.                                                 if(eggad->active==EG_LISTVIEW_NONE)
  552.                                                 {
  553.                                                     eggad->active=0L;
  554.                                                     addon=0;
  555.                                                 }
  556.                                             }
  557.  
  558.                                              if(shift)
  559.                                                 eggad->active=(LONG)MAX(eggad->active-addon, eggad->min);
  560.                                             else
  561.                                                 eggad->active=(LONG)MIN(eggad->active+addon, eggad->max);
  562.  
  563.                                             GT_SetGadgetAttrs(msg->IAddress=eggad->gadget, task->window, task->req,
  564.                                                                                 GTSL_Level,                msg->Code=(UWORD)eggad->active,
  565.                                                                                 GTSC_Top,                    msg->Code,
  566.                                                                                 GTPA_Color,                msg->Code,
  567.                                                                                 GTLV_Selected,        msg->Code,
  568.                                                                                 (KickStart<39 ? GTLV_Top : GTLV_MakeVisible), msg->Code,
  569.                                                                                 TAG_DONE);
  570.                                             CLEARBIT(msg->Class, IDCMP_RAWKEY);
  571.                                             if(eggad->kind==LISTVIEW_KIND)
  572.                                             {
  573.                                                 if(oldactive!=eggad->active)
  574.                                                     SETBIT(msg->Class, IDCMP_GADGETUP);
  575.                                             }
  576.                                             else
  577.                                                 SETBIT(msg->Class, IDCMP_MOUSEMOVE);
  578.                                         }
  579.                                         break;
  580.                                     case CHECKBOX_KIND:
  581.                                         eggad->active=!eggad->active;
  582.                                         GT_SetGadgetAttrs(msg->IAddress=eggad->gadget, task->window, task->req,
  583.                                                             GTCB_Checked,    msg->Code=(UWORD)eggad->active,
  584.                                                             TAG_DONE);
  585.                                         CLEARBIT(msg->Class, IDCMP_RAWKEY);
  586.                                         SETBIT(msg->Class, IDCMP_GADGETUP);
  587.                                         break;
  588.                                     case PALETTE_KIND:
  589.                                     case MX_KIND:
  590.                                         task->activegad=eggad;
  591.                                         egHandleMultipleChoiceKind(msg, task, shift);
  592.                                         break;
  593.                                 }
  594.                             }
  595.                         }
  596.                         else
  597.                             egShowAmigaGuide(eg, egGetHelpNode(task, msg));
  598.                         break;
  599.                     
  600.                     case IDCMP_CHANGEWINDOW:
  601.                         task->coords.LeftEdge    =task->window->LeftEdge;
  602.                         task->coords.TopEdge    =task->window->TopEdge;
  603.                         task->coords.Width        =task->window->Width;
  604.                         task->coords.Height        =task->window->Height;
  605.                         break;
  606.                     case IDCMP_MENUVERIFY:
  607.                     case IDCMP_INACTIVEWINDOW:
  608.                         if(task->activegad)
  609.                         {
  610.                             egSetGadgetState(task->activegad, task->window, FALSE);
  611.                             task->activegad=NULL;
  612.                             task->activekey=0;
  613.                         }
  614.                         break;
  615.                     case IDCMP_GADGETDOWN:
  616.                         if(msg->IAddress)
  617.                         {
  618.                             register struct egGadget *gad=egFindGadget(task->eglist, ((struct Gadget *)msg->IAddress)->GadgetID);
  619.  
  620.                             switch(gad->kind)
  621.                             {
  622.                                 case PALETTE_KIND:
  623.                                 case MX_KIND:
  624.                                     gad->active=(LONG)msg->Code;
  625.                                     break;
  626.                             }
  627.                         }
  628.                         break;
  629.                     case IDCMP_GADGETUP:
  630.                         if(msg->IAddress)
  631.                         {
  632.                             register struct egGadget *gad=egFindGadget(task->eglist, ((struct Gadget *)msg->IAddress)->GadgetID);
  633.  
  634.                             if(msg->IAddress==task->iconifygadget)
  635.                                 egIconify(task->eg, TRUE);
  636.                             else
  637.                             {
  638.                                 if(msg->Code==95) // help inside string
  639.                                     egShowAmigaGuide(eg, egGetHelpNode(task, msg));
  640.                                 if(gad)
  641.                                     switch(gad->kind)
  642.                                     {
  643.                                         case CYCLE_KIND:
  644.                                         case LISTVIEW_KIND:
  645.                                         case CHECKBOX_KIND:
  646.                                             gad->active=(LONG)msg->Code;
  647.                                             break;
  648.                                         case SLIDER_KIND:
  649.                                         case SCROLLER_KIND:
  650.                                             gad->active=(LONG)msg->Code;
  651.                                             break;
  652.                                     }
  653.                             }
  654.                         }
  655.                         break;
  656.                     case IDCMP_MOUSEMOVE:
  657.                         if(msg->IAddress)
  658.                         {
  659.                             register struct egGadget *gad=egFindGadget(task->eglist, ((struct Gadget *)msg->IAddress)->GadgetID);
  660.  
  661.                             if(gad)
  662.                                 switch(gad->kind)
  663.                                 {
  664.                                     case SLIDER_KIND:
  665.                                     case SCROLLER_KIND:
  666.                                         gad->active=(LONG)msg->Code;
  667.                                         break;
  668.                                 }
  669.                         }
  670.                 }
  671.                 if(msg!=NULL && task->handlefunc!=NULL)
  672.                     egCallHook(task->handlefunc, (APTR)msg);
  673.                 break;
  674.             }
  675.             }
  676.             break;
  677.         }
  678.     }
  679.     return msg;
  680. }
  681.  
  682. __asm __saveds LONG egSetGadgetAttrsA(register __a0 struct egGadget     *newgad,
  683.                                                                             register __a1 struct Window            *win,
  684.                                                                             register __a2 struct Requester    *req,
  685.                                                                             register __a3 struct TagItem        *taglist)
  686. {
  687.     struct TagItem    *tstate=taglist;
  688.     register struct TagItem    *tag;
  689.     register BYTE mark=FALSE, makevisible=FALSE;
  690.  
  691. #ifdef MYDEBUG_H
  692.     DebugOut("egSetGadgetAttrsA");
  693. #endif
  694.  
  695.     while(tag=NextTagItem(&tstate))
  696.         switch(tag->ti_Tag)
  697.         {
  698.             case GTCY_Labels:
  699.             case GTMX_Labels:
  700.                 newgad->labels=(STRPTR *)tag->ti_Data;
  701.                 break;
  702.             case GTLV_Labels:
  703.                 if(tag->ti_Data==~0)
  704.                     newgad->list=NULL;
  705.                 else
  706.                     newgad->list=(struct List *)tag->ti_Data;
  707.                 break;
  708.             case GTLV_Top:
  709.                 newgad->min=(WORD)tag->ti_Data;
  710.                 break;
  711.             case GTCY_Active:
  712.             case GTMX_Active:
  713.             case GTCB_Checked:
  714.             case GTPA_Color:
  715.             case GTLV_Selected:
  716.             case GTSL_Level:
  717.                 newgad->active=(LONG)tag->ti_Data;
  718.                 break;
  719.             case GTLV_SelectedNode:
  720.                 {
  721.                     register struct Node *node, *marknode=(struct Node *)tag->ti_Data;
  722.                     register LONG select=0;
  723.  
  724.                     if(!IsNil(newgad->list))
  725.                         for(node=newgad->list->lh_Head;node->ln_Succ;node=node->ln_Succ)
  726.                             if(marknode==node)
  727.                             {
  728.                                 newgad->active=select;
  729.                                 mark=TRUE;
  730.                                 tag->ti_Tag=TAG_IGNORE;
  731. //                                tag->ti_Data=select;
  732.                                 break;
  733.                             }
  734.                             else
  735.                                 ++select;
  736.                 }
  737.                 break;
  738.             case GTSL_Min:
  739.                 newgad->min=(WORD)tag->ti_Data;
  740.                 break;
  741.             case GTSL_Max:
  742.                 newgad->max=(WORD)tag->ti_Data;
  743.                 break;
  744.             case GTPA_Depth:
  745.                 newgad->max=(WORD)1<<tag->ti_Data;
  746.                 break;
  747.             case GA_Disabled:
  748.                 if(tag->ti_Data)
  749.                     if(ISBITSET(newgad->flags, EG_DISABLED))
  750.                         tag->ti_Tag=TAG_IGNORE;
  751.  
  752.                 IFTRUESETBIT(tag->ti_Data, newgad->flags, EG_DISABLED);
  753.  
  754.                 if(newgad->kind>=EG_GETFILE_KIND)
  755.                     if(ISBITSET(newgad->flags, EG_DISABLED))
  756.                         OffGadget(newgad->gadget, win, req);
  757.                     else
  758.                         OnGadget(newgad->gadget, win, req);
  759.                 break;
  760.             case GTLV_MakeVisible:
  761.                 mark=makevisible=TRUE;
  762.                 if(tag->ti_Data>newgad->active)
  763.                     newgad->active=tag->ti_Data;
  764.                 else
  765.                 {
  766. //                    UWORD scrollrows=(H(listview)/listview->ng.ng_TextAttr->ta_YSize)-1,
  767. //                                top;
  768.  
  769. //                    if(newgad->active-
  770.                 }
  771.                 break;
  772.         }
  773.     if(mark)
  774.         GT_SetGadgetAttrs(newgad->gadget, win, req,
  775.                                         GTLV_Selected,        (UWORD)newgad->active,
  776.                                         (KickStart>38 ? GTLV_MakeVisible:GTLV_Top),    (UWORD)newgad->active,
  777.                                         TAG_MORE, taglist,
  778.                                         TAG_END);
  779.     else
  780.         GT_SetGadgetAttrsA(newgad->gadget, win, req, taglist);
  781.  
  782.     return newgad->active;
  783. }
  784.  
  785. __asm __saveds struct Node *egGetNode(register __a0 struct List *list,
  786.                                                                             register __d0 ULONG                selected)
  787. {
  788.     register struct Node *node;
  789.     register UWORD i=0;
  790.  
  791. #ifdef MYDEBUG_H
  792.     DebugOut("egGetSelectedNode");
  793. #endif
  794.  
  795.     if(!IsNil(list))
  796.         for(every_node)
  797.             if(i==selected)
  798.                 return node;
  799.             else
  800.                 ++i;
  801.  
  802.     return NULL;
  803. }
  804.  
  805. __asm __saveds void egGetGadgetAttrsA(register __a0 struct egGadget     *newgad,
  806.                                                                             register __a1 struct Window            *win,
  807.                                                                             register __a2 struct Requester    *req,
  808.                                                                             register __a3 struct TagItem        *taglist)
  809. {
  810.         struct TagItem    *tstate=taglist;
  811.         register struct TagItem    *tag;
  812.         ULONG                        *p;
  813.  
  814. #ifdef MYDEBUG_H
  815.     DebugOut("egGetGadgetAttrsA");
  816. #endif
  817.  
  818.     if(KickStart>38)
  819.         GT_SetGadgetAttrsA(newgad->gadget, win, req, taglist);
  820.     else
  821.         while(tag=NextTagItem(&tstate))
  822.         {
  823.             p=(ULONG *)tag->ti_Data;
  824.  
  825.             switch(tag->ti_Tag)
  826.             {
  827.                 case GA_Disabled:
  828.                     *p=(ULONG)ISBITSET(newgad->flags, EG_DISABLED);
  829.                     break;
  830.                 case GTCB_Checked:
  831.                 case GTCY_Active:
  832.                 case GTMX_Active:
  833.                 case GTPA_Color:
  834.                 case GTLV_Selected:
  835.                     *p=(ULONG)newgad->active;
  836.                     break;
  837.                 case GTCY_Labels:
  838.                     *p=(ULONG)newgad->labels;
  839.                     break;
  840.                 case GTIN_Number:
  841.                     *p=(ULONG)Number(newgad);
  842.                     break;
  843.                 case GTLV_Labels:
  844.                     *p=(ULONG)newgad->list;
  845.                     break;
  846.                 case GTLV_Top:
  847.                     *p=*(short *)(((char *)newgad->gadget)+sizeof(struct Gadget)+6);
  848.                     break;
  849.                 case GTSC_Top:
  850.                 case GTSL_Level:
  851.                     *p=(ULONG)newgad->active;
  852.                     break;
  853.                 case GTSC_Total:
  854.                     break;
  855.                 case GTSC_Visible:
  856.                     break;
  857.                 case GTSL_Min:
  858.                     *p=(ULONG)newgad->min;
  859.                     break;
  860.                 case GTSL_Max:
  861.                     *p=(ULONG)newgad->max;
  862.                     break;
  863.                 case GTST_String:
  864.                     *p=(ULONG)String(newgad);
  865.                     break;
  866.             }
  867.         }
  868.     if(tag=FindTagItem(GTLV_SelectedNode, taglist))
  869.     {
  870.         p=(ULONG *)tag->ti_Data;
  871.         *p=(ULONG)egGetNode(newgad->list, newgad->active);
  872.     }
  873. }
  874.  
  875. #endif
  876.